<template>
  <div class="wh">
    <commonshownum :type="'shishi'" :num="numval" :typestr.sync="typestr" :componentDetail="componentDetail"/>
  </div>
</template>
<script>
import commonmixins from "@/mixins/bigScreen/commonmixins";
import axios from "@/utils/requestdp";
import dayjs from "dayjs";

export default {
  mixins: [commonmixins],
  name: "shishinumtaian",
  components: {},
  data() {
    return {
      numval: "-",
      typestr: "实时供热量·MW",
    };
  },
  computed: {},
  watch: {
    "$store.state.daping.bigScreen": {
      handler: function (n, o) {
        let n_tmp = n;
        let g_bigscreen_data_arr = n_tmp.filter((item) => {
          if (item.attrName == "plan_heat") {
            return true;
          }
        });
        this.numval = g_bigscreen_data_arr[0].attrValue;
      },
    },
  },
  computed: {},
  mounted() {
    this.watchEvent();
  },
  methods: {
    watchEvent() {
      //先清除定时任务
      if (this.$store.state.daping.intervalArr["shishinumtaian"] != undefined) {
        return;
      }
      this.loadData();
      let interval = setInterval(() => {
        this.loadData();
      }, this.$root.setting.data.interval);
      this.$store.state.daping.intervalArr["shishinumtaian"] = [
        { interval: interval },
      ];
    },
    loadData() {
      let day = dayjs().format("YYYY-MM-DD");

      let st = dayjs(day + " 00:00:00").unix();
      let et = dayjs(day + " 23:59:59").unix();


      let queryJson = {
        queries: [
          {
            metric: "id,sa_003qc",
            schema: "dwb",
          },
        ],
        endTime: et,
        startTime: st,
        table: "pipenet_m",
        orderBy: "aligntime",
        search: "id=0",
        type: 'history',
        needType: false,

      };

      axios.post("/open/queryDb", queryJson).then((res) => {
        console.log(res)
        if (res.code == 200 && res.data[0]) {
          this.$store.state.daping.shishinumtaian = res.data[0]['sa_001heatare'];
          // 暂无数据
          // this.numval = parseInt(res.data[0]['sa_001heatare'])
        }
      });
    },
  }
};
</script>
<style lang='scss' scoped>
</style>